<?php

use yii\helpers\Inflector;
use yii\helpers\StringHelper;

/* @var $this yii\web\View */
/* @var $generator yii\gii\generators\crud\Generator */

$urlParams = $generator->generateUrlParams();
$nameAttribute = $generator->getNameAttribute();

echo "<?php\n";
?>

use yii\helpers\Html;
use <?= $generator->indexWidgetType === 'grid' ? "yii\\grid\\GridView" : "yii\\widgets\\ListView" ?>;
<?= $generator->enablePjax ? 'use yii\widgets\Pjax;' : '' ?>

/* @var $this yii\web\View */
<?= !empty($generator->searchModelClass) ? "/* @var \$searchModel " . ltrim($generator->searchModelClass, '\\') . " */\n" : '' ?>
/* @var $dataProvider yii\data\ActiveDataProvider */

$this->title = <?= $generator->generateString(Inflector::pluralize(Inflector::camel2words(StringHelper::basename($generator->modelClass)))) ?>;
$this->params['breadcrumbs'][] = $this->title;
?>
<div class="<?= Inflector::camel2id(StringHelper::basename($generator->modelClass)) ?>-index">

    <h1><?= "<?= " ?>Html::encode($this->title) ?></h1>

    <p>
        <?= "<?= " ?>Html::a(<?= $generator->generateString('Create ' . Inflector::camel2words(StringHelper::basename($generator->modelClass))) ?>, ['create'], ['class' => 'btn btn-success']) ?>
    </p>

<?= $generator->enablePjax ? "    <?php Pjax::begin(); ?>\n" : '' ?>
<?php if(!empty($generator->searchModelClass)): ?>
<?= "    <?php " . ($generator->indexWidgetType === 'grid' ? "// " : "") ?>echo $this->render('_search', ['model' => $searchModel]); ?>
<?php endif; ?>

<?php if ($generator->indexWidgetType === 'grid'): ?>
    <?= "<?= " ?>GridView::widget([
        'dataProvider' => $dataProvider,
    'layout'=> "{summary}\n{items}\n{pager}",
   // 'summary' => "{begin} - {end} {count} {totalCount} {page} {pageCount}",
    'summary' => "第{begin} - {end}条   共{totalCount}条数据",
    'pager'=>[
    //'options'=>['class'=>'hidden']//关闭自带分页
    'firstPageLabel' =>"首页",
    'prevPageLabel'  =>'上一页',
    'nextPageLabel'  =>'下一页',
    'lastPageLabel'  =>'最后',
    'maxButtonCount' => 6,
    ],
        <?= !empty($generator->searchModelClass) ? "'filterModel' => \$searchModel,\n        'columns' => [\n" : "'columns' => [\n"; ?>
    ['class' => 'yii\grid\SerialColumn'],


<?php
$count = 0;
if (($tableSchema = $generator->getTableSchema()) === false) {
    foreach ($generator->getColumnNames() as $name) {
        if (++$count < 6) {
            echo "            '" . $name . "',\n";
        } else {
            echo "            //'" . $name . "',\n";
        }
    }
} else {
    foreach ($tableSchema->columns as $column) {
        $format = $generator->generateColumnFormat($column);
        echo "            ['attribute'=> '" . $column->name . "'],\n";

    }
}
?>

            ['class' => 'yii\grid\ActionColumn',
             'header' => '操作',
             'template' => '{view} {update} {delete}',
             'buttons' => [
                  'view' => function ($url,$model,$key)   { return Html::a('<span class="glyphicon glyphicon-eye-open"></span>', [$url], ['title' => '查看']); },
                  'update' => function ($url,$model,$key) { return Html::a('<span class="glyphicon glyphicon-pencil"></span>', [$url], ['title' => '编辑']); },
                  'delete' => function ($url,$model, $key) { return Html::a('<span class="glyphicon glyphicon-trash"></span>', [$url], ['title' => '删除', 'data-method' => 'post','data-confirm' => "sure delete?"]);},

    ],
    ],
        ],
    ]); ?>
<?php else: ?>
    <?= "<?= " ?>ListView::widget([
        'dataProvider' => $dataProvider,
        'itemOptions' => ['class' => 'item'],
        'itemView' => function ($model, $key, $index, $widget) {
            return Html::a(Html::encode($model-><?= $nameAttribute ?>), ['view', <?= $urlParams ?>]);
        },
    ]) ?>
<?php endif; ?>

<?= $generator->enablePjax ? "    <?php Pjax::end(); ?>\n" : '' ?>

</div>
